package game.players.user;

import com.uqbar.vainilla.DeltaState;
import com.uqbar.vainilla.appearances.Sprite;
import com.uqbar.vainilla.events.constants.Key;

import game.players.SoccerPlayer;
import game.players.SoccerPlayerCPU;
import game.players.cpu.teammate.WithoutBallStationaryCPUMate;
import game.players.states.BeatenPlayer;
import game.players.user.movements.WithoutBallStationaryUser;
import game.scene.MatchScene;

public class BeatenUserPlayer extends BeatenPlayer {

	public BeatenUserPlayer(SoccerPlayer player, boolean isRight) {
		super(player, isRight);
	}
	
	@Override
	public void update(DeltaState deltaState) {
		if (deltaState.isKeyPressed(Key.C)) {
			MatchScene scene = this.getPlayer().getScene();
			SoccerPlayerCPU closerBallPlayer = scene.getCloserBallTeammate(this.getPlayer());
			this.getPlayer().getScene().changeFromUserToCPU(this.getPlayer(), closerBallPlayer);
		}
		super.update(deltaState);
	}

	@Override
	public void finishBeaten() {
		if (this.getPlayer().isWithPlayingMark())
			this.getPlayer().setState(new WithoutBallStationaryUser(this.getPlayer()));
		else
			this.getPlayer().setState(new WithoutBallStationaryCPUMate(this.getPlayer()));
	}

	@Override
	public boolean isWithBall() {
		return false;
	}

	@Override
	public void setRightSprite() {
		this.getPlayer().setAppearance(Sprite.fromImage("/images/goal3_golpeado2.png").scale(1.5).flipHorizontally());
	}

	@Override
	public void setLeftSprite() {
		this.getPlayer().setAppearance(Sprite.fromImage("/images/goal3_golpeado2.png").scale(1.5));
	}

}
